﻿#include "fradddialog.h"
#include "ui_fradddialog.h"
#include <QMessageBox>
#include <QtSql>


AddFileRDlg::AddFileRDlg(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::AddFileRDlg)
{
    ui->setupUi(this);
    ui->frame->resize(this->geometry().width(), ui->frame->height());
    ui->status->setText("添加信息状态：");
    ui->dtEdtFile->setDate(QDate::currentDate());
    ui->dtEdtLbry->setDate(QDate::currentDate());
    connect(ui->btnOkA,SIGNAL(clicked(bool)),parent,SLOT(FRshowdatabase()));
}

AddFileRDlg::~AddFileRDlg()
{
    delete ui;}

void AddFileRDlg::on_btnOkA_clicked()
{
    strFileFormUnit = ui->edtFromUnitA->text();//转档单位（人）
    strFileToUnit = ui->edtToUnitA->text();//接收人
    strFileName = ui->edtNameA->text(); //姓名
    strIDType = ui->cbBxIDType->currentText();//身份类型
    if(strIDType == QString("居民身份证")){
        strIDType = "1";
    }else if(strIDType == QString("军官证")){
        strIDType = "2";
    }else if(strIDType == QString("士官证")){
        strIDType = "3";
    }else if(strIDType == QString("义务兵证")){
        strIDType = "4";
    }else if(strIDType == QString("港澳台居民居住证")){
        strIDType = "5";
    }else if(strIDType == QString("外籍人士在我国永久居住证")){
        strIDType = "6";
    }else if(strIDType == QString("护照")){
        strIDType = "7";
    }else if(strIDType == QString("其他")){
        strIDType = "9";
    }
    strID = ui->edtID->text();//证件号码
    strFileSex = ui->cbBxSex->currentText();//性别
    strFilePlace = ui->edtPlaceA->text();//籍贯
    strFileNowDuty = ui->edtNowDutyA->text();//现单位职务
    strFIleDescription = ui->edtDescriptionA->toPlainText();//备注
    strFileRDate = ui->dtEdtFile->date().toString("yyyy-MM-dd");//接收时间
    strFileLbryDate = ui->dtEdtLbry->date().toString("yyyy-MM-dd");//入库时间
    if(strFileFormUnit.trimmed().isEmpty()){//120
        ui->status->setText("添加信息状态：请输入转档单位（人）！");
    }else if(strFileFormUnit.size() > 120){
        ui->status->setText("添加信息状态：转档单位（人）信息字数超出！！");
    }else if(strFileToUnit.trimmed().isEmpty()){
        ui->status->setText("添加信息状态：请输入接收人！");
    }else if(strFileToUnit.size() > 50){//50
        ui->status->setText("添加信息状态：接收人信息字数超出！");
    }else if(strFileName.trimmed().isEmpty()){
        ui->status->setText("添加信息状态：请输入姓名！");
    }else if(strFileName.size() > 50){//50
        ui->status->setText("添加信息状态：姓名信息输入错误！");
    }else if(strID.trimmed().isEmpty()){
        ui->status->setText("添加信息状态：请输入证件号码！");
    }else if(strID.size() > 18 ){
        ui->status->setText("添加信息状态：请输入正确的证件号码！");
    }else if(strFilePlace.trimmed().isEmpty()){
        ui->status->setText("添加信息状态：请输入籍贯信息！");
    }else if(strFilePlace.trimmed().isEmpty()){//80
        ui->status->setText("添加信息状态：籍贯信息字数超出！");
    }else if(strFileNowDuty.trimmed().isEmpty()){
        ui->status->setText("添加信息状态：请输入现单位职务！");
    }else if(strFileNowDuty.size() > 80){//80
        ui->status->setText("添加信息状态：现单位职务信息字数超出！");
    }else if(strFIleDescription.size() > 500 ){//500
        ui->status->setText("添加信息状态：备注信息输入字数超出500字！");
    }else{
        QString strInsert=QString("insert into FileReceive values (null,'%1','%2','%3','%4','%5','%6','%7','%8','%9','%10','%11'); ")
                .arg(strFileFormUnit).arg(strFileToUnit).arg(strFileName).arg(strIDType).arg(strID).arg(strFileSex)
                .arg(strFilePlace).arg(strFileNowDuty).arg(strFIleDescription).arg(strFileRDate).arg(strFileLbryDate);
        QSqlQuery query;
        if(query.exec(strInsert)){
            ui->status->setText("添加信息状态：信息登记成功！");
            ui->edtDescriptionA->clear();
            ui->edtFromUnitA->clear();
            ui->edtID->clear();
            ui->edtNameA->clear();
            ui->edtNowDutyA->clear();
            ui->edtPlaceA->clear();
            ui->edtToUnitA->clear();
        }else{
            ui->status->setText("添加信息状态：信息登记失败！");
        }
    }

}

void AddFileRDlg::on_btnCancelA_clicked()
{
    this->close();
}
